﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class Control_TiepNhan_HoSoChoXuLy
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim _IsUser As Integer = Session("IsUser")
            BindToGrid(_IsUser)
        End If
    End Sub

    Protected Sub BindToGrid(ByVal _LoaiNguoiDung As Integer)


        Using _data As New VSEntities
            ' mot cua
            Dim curHuyenId As Integer = Session("HuyenId")
            If _LoaiNguoiDung = LoaiNguoiDung.MotCua Then
                motcua.Visible = True
                'tiêp nhân người dân và một cửa
                Dim _p = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.Nhap Order By q.Created Descending Select q).ToList
                ltrSoluong.Text = _p.Count
                Dim p = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.Nhap Order By q.Created Descending Select q).Take(18).ToList
                With rptTiepNhan
                    .DataSource = p
                    .DataBind()
                End With
                'chuyển phong tài chính kế hoạch xử lý
                Dim _k = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ChoDuyet Order By q.Created Descending Select q).ToList
                ltrSoluongCho.Text = _k.Count
                Dim k = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.ChoDuyet Order By q.Created Descending Select q).Take(18).ToList
                With rptChoXuLy
                    .DataSource = k
                    .DataBind()
                End With
                'xem hồ sơ phòng tài chính đã tiếp nhận
                Dim _h = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.Daduyet Order By q.Created Descending Select q).ToList
                ltrDangXuly.Text = _h.Count
                Dim h = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.Daduyet Order By q.Created Descending Select q).Take(18).ToList
                With rptPTCKH
                    .DataSource = h
                    .DataBind()
                End With
                'phòng tài chính kế hoạch duyệt chờ ký hoàn tất
                Dim _l As List(Of uspCertifiedHouseholdSelectAll_Result) = _data.uspCertifiedHouseholdSelectAll("", "1900-01-01 00:00:00", "3999-12-31 00:00:00", "", "", -1, "", "" _
                                                                                                                , "1900-01-01 00:00:00", "3999-12-31 00:00:00", "", "", "", "", "", "", "", "" _
                                                                                                                , "", "", -1, curHuyenId, 1, 10).ToList
                If _l.Count > 0 Then
                    ltrHoanTat.Text = _l.FirstOrDefault.Total()
                End If
                Dim l = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.Hoantat Order By q.Created Descending Select q).Take(18).ToList
                With rptHoanTat
                    .DataSource = l
                    .DataBind()
                End With
                'hồ sơ bị trả về
                Dim _j = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.TraVe Order By q.Created Descending Select q).ToList
                ltrTraVe.Text = _j.Count
                Dim j = (From q In _data.CertifiedHouseholds Where q.ProvinceId = curHuyenId And q.StatusId = TinhTrangHoSo.TraVe Order By q.Created Descending Select q).Take(18).ToList
                With rptTraVe
                    .DataSource = j
                    .DataBind()
                End With

            ElseIf _LoaiNguoiDung = LoaiNguoiDung.TCKH Then
            End If
        End Using
    End Sub
    Protected Sub rptTiepNhan_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptTiepNhan.ItemDataBound, rptChoXuLy.ItemDataBound, rptHoanTat.ItemDataBound, rptTraVe.ItemDataBound, rptPTCKH.ItemDataBound
        Using _data As New VSEntities
            Dim row = CType(e.Item.DataItem, CertifiedHousehold)
            Dim hplTitle As HyperLink = e.Item.FindControl("hplTitle")
            Dim _NgayTao As String
            If Not row.Created Is Nothing Then
                _NgayTao = CType(row.Created, Date).ToString("dd/MM/yyyy")
            Else
                _NgayTao = ""
            End If
            hplTitle.Text = row.Ow_Name & " - " & "Ngày nhận: " & _NgayTao
            hplTitle.NavigateUrl = "../../Page/TiepNhan/Detail.aspx?Certifiedid=" & row.CertifiedID
        End Using
    End Sub
End Class
